package com.ruoyi.pay.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.pay.domain.PayConfig;
import com.ruoyi.pay.mapper.PayConfigMapper;
import com.ruoyi.pay.service.IPayConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;


/**
 * 支付配置Service业务层处理
 *
 * @author ruoyi
 * @date 2024-12-02
 */
@Service
public class PayConfigServiceImpl extends ServiceImpl<PayConfigMapper, PayConfig> implements IPayConfigService {
    @Autowired
    private PayConfigMapper payConfigMapper;

    /**
     * 查询支付配置
     *
     * @param id 支付配置主键
     * @return 支付配置
     */
    @Override
    public PayConfig selectPayConfigById(Long id) {
        return payConfigMapper.selectPayConfigById(id);
    }

    /**
     * 查询支付配置列表
     *
     * @param payConfig 支付配置
     * @return 支付配置
     */
    @Override
    public List<PayConfig> selectPayConfigList(PayConfig payConfig) {
        return payConfigMapper.selectPayConfigList(payConfig);
    }

    /**
     * 新增支付配置
     *
     * @param payConfig 支付配置
     * @return 结果
     */
    @Override
    public HashMap<String, String> insertPayConfig(PayConfig payConfig) {
        HashMap<String, String> map = new HashMap<>();
        //查询是否已有默认选中的数据
        QueryWrapper<PayConfig> wrapper = new QueryWrapper<>();
        wrapper.eq("is_check", 0);
        PayConfig one = payConfigMapper.selectOne(wrapper);
        if(one != null){
             map.put("msg", "已有默认选中的数据,请修改默认选中状态");
             return map;
         }
        map.put("code","200");
        map.put("msg", "添加成功");
        payConfigMapper.insertPayConfig(payConfig);
        return map;
    }

    /**
     * 修改支付配置
     *
     * @param payConfig 支付配置
     * @return 结果
     */
    @Override
    public int updatePayConfig(PayConfig payConfig) {
        return payConfigMapper.updatePayConfig(payConfig);
    }

    /**
     * 批量删除支付配置
     *
     * @param ids 需要删除的支付配置主键
     * @return 结果
     */
    @Override
    public int deletePayConfigByIds(Long[] ids) {
        return payConfigMapper.deletePayConfigByIds(ids);
    }

    /**
     * 删除支付配置信息
     *
     * @param id 支付配置主键
     * @return 结果
     */
    @Override
    public int deletePayConfigById(Long id) {
        return payConfigMapper.deletePayConfigById(id);
    }
}

